import {
  Message
} from 'element-ui'
import {
  isObject,
  isArray
} from 'lodash'

/**
 * Utility function for processing the response of http call using axios.
 * @param {*} response Response object
 * @return Promise
 */
export const processResponse = response => {
  return response
    .then(res => {
      if (isArray(res.data)) {
        return res.data
      } else if (isObject(res.data)) {
        return {
          ...res.data
        }
      } else {
        return res.data
      }
    })
    .catch(err => {
      err.response && Message.error(err.response.data.message)
      // throw err
    })
}
